import { JupiterCategory, JupiterCategoryQuery } from '../types/categoryTypes';
import request from 'utils/request';

// 获取分类列表
export const fetchCategoryList = (params: JupiterCategoryQuery) => {
  return request.post('/categories/page', params);
};

// 获取所有分类
export const fetchAllCategories = () => {
  return request.get('/categories');
};

// 根据UUID获取分类
export const fetchCategoryById = (uuid: string) => {
  return request.get(`/categories/${uuid}`);
};

// 创建分类
export const createCategory = (data: Partial<JupiterCategory>) => {
  return request.post('/categories', data);
};

// 更新分类
export const updateCategory = (uuid: string, data: Partial<JupiterCategory>) => {
  return request.put(`/categories/${uuid}`, data);
};

// 删除分类
export const deleteCategory = (uuid: string) => {
  return request.delete(`/categories/${uuid}`);
};

// 批量删除分类
export const batchDeleteCategories = (uuids: string[]) => {
  return request.delete('/categories/batch', { data: { uuids } });
};

// 获取分类树
export const fetchCategoryTree = () => {
  return request.get('/categories/tree');
};

// 根据父级UUID获取子分类列表
export const fetchCategoriesByParent = (parentUuid: string) => {
  return request.get(`/categories/parent/${parentUuid}`);
};

// 获取激活状态的分类列表
export const fetchActiveCategories = () => {
  return request.get('/categories/active');
};

// 获取分类的文章数量
export const fetchCategoryArticleCount = (uuid: string) => {
  return request.get(`/categories/${uuid}/article-count`);
};

// 更新分类排序
export const updateCategorySort = (uuid: string, sortOrder: number) => {
  return request.put(`/categories/${uuid}/sort`, { sortOrder });
};
